package org.zpmis.api.http;

import org.springframework.validation.annotation.Validated;
import org.zpmis.api.business.SysMenuWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.role.qo.*;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description:
* @author  Yang
* date: 2021-5-31
* time: 14:00:27
*/
@RestController
@RequestMapping("/menu")
@Slf4j
public class SysMenuController extends BaseController{

    @Resource
    private SysMenuWebService sysMenuWebService;

    /**
     * 新增菜单
     * @param addSysMenuQo
     * @return
     */
    @PostMapping("/addSysMenu")
    public PlatformResult addSysMenu(@Validated @RequestBody AddSysMenuQo addSysMenuQo){
        try {
            sysMenuWebService.addSysMenu(addSysMenuQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[SysMenuController]---addSysMenu--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---addSysMenu--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 修改菜单
     * @param editSysMenuQo
     * @return
     */
    @PostMapping("/editSysMenu")
    public PlatformResult editSysMenu(@Validated @RequestBody EditSysMenuQo editSysMenuQo){
        try {
            sysMenuWebService.editSysMenu(editSysMenuQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[SysMenuController]---editSysMenu--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---editSysMenu--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 删除菜单
     * @param delSysMenuQo
     * @return
     */
    @PostMapping("/delSysMenu")
    public PlatformResult delSysMenu(@Validated @RequestBody DelSysMenuQo delSysMenuQo){
        try {
            sysMenuWebService.delSysMenu(delSysMenuQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[SysMenuController]---delSysMenu--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---delSysMenu--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 菜单列表
     * @param sysMenuListQo
     * @return
     */
    @PostMapping("/sysMenuList")
    public PlatformResult sysMenuList(@Validated @RequestBody SysMenuListQo sysMenuListQo){
        try {
            return PlatformResult.success(sysMenuWebService.sysMenuList(sysMenuListQo));
        } catch (BusinessException e) {
            log.error("[SysMenuController]---sysMenuList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---sysMenuList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 菜单父级列表
     * @param
     * @return
     */
    @PostMapping("/sysMenuParentList")
    public PlatformResult sysMenuParentList(){
        try {
            return PlatformResult.success(sysMenuWebService.sysMenuParentList());
        } catch (BusinessException e) {
            log.error("[SysMenuController]---sysMenuParentList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---sysMenuParentList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 获取用户登录之后的菜单
     * @param
     * @return
     */
    @PostMapping("/getUserSysMenu")
    public PlatformResult getUserSysMenu(){
        try {
            return PlatformResult.success(sysMenuWebService.getUserSysMenu());
        } catch (BusinessException e) {
            log.error("[SysMenuController]---getUserSysMenu--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---getUserSysMenu--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 角色分配菜单数据查询
     * @param sysMenuListQo
     * @return
     */
    @PostMapping("/roleDistributionMenuList")
    public PlatformResult roleDistributionMenuList(@Validated @RequestBody SysMenuListQo sysMenuListQo){
        try {
            return PlatformResult.success(sysMenuWebService.sysMenuList(sysMenuListQo));
        } catch (BusinessException e) {
            log.error("[SysMenuController]---roleDistributionMenuList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[SysMenuController]---roleDistributionMenuList--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
